﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
using StockFinder.Indicators.Day;
using StockFinder.Indicators.Day.ClosePrice;
using StockFinder.Model;
using StockFinder.Model.Constants;
using StockFinder.Model.Enumerations;
using StockFinder.StockLists;
using System.Diagnostics;
using StockFinder.StockLists.Exchanges;
using StockFinder.StockLists.Indexes;

namespace Testharness
{
    public partial class StockListForm : Form
    {
        public StockListForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var entireNasdaqStockList = new NasdaqOnlineAllNasdaqYahooFinanceOnlinePricesStockList();

            foreach (var item in entireNasdaqStockList)
            {

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var entireNyseStockList = new NasdaqOnlineAllNyseYahooFinanceOnlinePricesStockList();

            foreach (var item in entireNyseStockList)
            {

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            var entireAmexStockList = new NasdaqOnlineAllAmexYahooFinanceOnlinePricesStockList();

            foreach (var item in entireAmexStockList)
            {

            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            var norgateNasdaqOffline = new NorgateOfflineAllNasdaqNorgatePriceLoaderStockList();

            foreach (var item in norgateNasdaqOffline)
            {
                Debug.WriteLine(string.Format("{0} | {1}", item.Name, item.Prices.Count));
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            var allNasdaqOnline = new NasdaqOnlineAllYahooFinanceOnlinePricesStockList();

            var stopWatch = new Stopwatch();
            stopWatch.Start();

            foreach (var item in allNasdaqOnline)
            {
                Debug.WriteLine(string.Format("{0} | {1}", item.Name, 
                    (item.Prices == null)?0:item.Prices.Count));
            }

            Debug.WriteLine(string.Format("{0}", stopWatch.Elapsed.TotalSeconds));
        }

        private void button6_Click(object sender, EventArgs e)
        {
            const string OFFLINE_DIRECTORY = @"C:\NasdaqOnlineAllYahooFinancePriceHistories";
            var yahooOffline = new YahooFinanceOfflineDirectoryBrowserStockList(){ DirectoryLocation = OFFLINE_DIRECTORY};            

            var stopWatch = new Stopwatch();
            stopWatch.Start();

            foreach (var item in yahooOffline)
            {                
                Debug.WriteLine(string.Format("{0} | {1}", item.Name, item.Prices.Count));

                var prices = item.Prices;
                var pricesAscending = item.Prices.OrderBy(p => p.PriceDate);
                var ascArray = pricesAscending.ToArray();
                var pricesDescending = item.Prices.OrderByDescending(p => p.PriceDate);
                var desArray = pricesDescending.ToArray();
            }

            Debug.WriteLine(string.Format("{0}", stopWatch.Elapsed.TotalSeconds));
        }

        private void button7_Click(object sender, EventArgs e)
        {
            var stocks = new FinvizOnlineDowJonesStockList { LoadPrices = true };
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            foreach (var item in stocks)
            {                
                Debug.WriteLine(string.Format("{0} | {1}", item.Name, item.Prices.Count));
            }

            Debug.WriteLine(string.Format("{0}", stopWatch.Elapsed.TotalSeconds));
        }

        private void button8_Click(object sender, EventArgs e)
        {
            var stocks = new FinvizOnlineSnP500StockList{ LoadPrices = false };

            foreach (var item in stocks)
            {
                Debug.WriteLine(string.Format("{0} | {1}", item.Name, item.Prices.Count));
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            var stocks = new LseOnlineFtse100StockList { LoadPrices = false };

            foreach (var item in stocks)
            {
                Debug.WriteLine(string.Format("{0} | {1}", item.Name, item.Prices.Count));
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            var stocks = new TelegraphOnlineFtse100StockList { LoadPrices = false };

            foreach (var item in stocks)
            {
                Debug.WriteLine(string.Format("{0} | {1}", item.Name, item.Prices.Count));
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            var stocks = new TelegraphOnlineFtse250StockList { LoadPrices = true };

            foreach (var item in stocks)
            {
                Debug.WriteLine(string.Format("{0} | {1}", item.Name, (item.Prices != null) ? item.Prices.Count.ToString() : "N/A"));
            }
        }
    }
}
